#ifndef __EGLWindow_H__
#define __EGLWindow_H__


#include "U2GLESPreRequest.h"
#include "U2RenderWindow.h"



U2EG_NAMESPACE_BEGIN


class U2EGLSupport;
class U2EGLContext;


class _U2GLESShare U2EGLWindow : public U2RenderWindow
{
protected:
    bool            mClosed;
    bool            mVisible;
    bool            mIsTopLevel;
    bool            mIsExternal;
    bool            mIsExternalGLControl;

    U2EGLSupport*   mGLSupport;
    U2EGLContext*   mContext;
	NativeWindowType    mWindow;
	NativeDisplayType   mNativeDisplay;
	::EGLDisplay    mEglDisplay;


	::EGLConfig     mEglConfig;
	::EGLSurface    mEglSurface;

    ::EGLSurface createSurfaceFromWindow(::EGLDisplay display, NativeWindowType win);

	virtual void switchFullScreen(bool fullscreen) = 0;
	virtual U2EGLContext * createEGLContext() const = 0;
	virtual void getLeftAndTopFromNativeWindow(int & left, int & top, u2uint width, u2uint height) = 0;
	virtual void initNativeCreatedWindow(const NameValuePairList *miscParams) = 0;
	virtual void createNativeWindow( int &left, int &top, u2uint &width, u2uint &height, U2String &title ) = 0;
	virtual void reposition(int left, int top) = 0;
	virtual void resize(unsigned int width, unsigned int height) = 0;
	virtual void windowMovedOrResized() = 0;

public:
    U2EGLWindow(U2EGLSupport* glsupport);
    virtual ~U2EGLWindow();

	virtual void setFullscreen (bool fullscreen, u2uint width, u2uint height);
    void destroy(void);
    bool isClosed(void) const;
    bool isVisible(void) const;
    void setVisible(bool visible);
    void swapBuffers(bool waitForVSync);
    void copyContentsToMemory(const U2PixelBox &dst, FrameBuffer buffer);

    /** Get custom attribute; the following attributes are valid:
        WINDOW         The X NativeWindowType target for rendering.
        GLCONTEXT      The U2 GLContext used for rendering.
        DISPLAY        EGLDisplay connection behind that context.
        DISPLAYNAME    The name for the connected display.
    */
    virtual void getCustomAttribute(const U2String& name, void* pData);

    bool requiresTextureFlipping() const;
};


U2EG_NAMESPACE_END


#endif
